package com.jmag.nop.gateway.config;

import com.jmag.nop.gateway.common.bean.ApiConfig;
import com.jmag.nop.gateway.common.gateway.configuration.AlipayGatewayConfiguration;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName GatewayConfig
 * @Description TODO
 * @Author JMAG
 **/
//@Configuration
public class GatewayConfig extends AlipayGatewayConfiguration {
    //@Bean
    /*XXXFilter xxxFilter() {
        return new XXXFilter();
    }*/

    @Override
    protected void doAfter() {
        ApiConfig.getInstance().setTokenValidator(apiParam -> {
            // 获取客户端传递过来的token
            String token = apiParam.fetchAccessToken();
            if (StringUtils.isBlank(token)) {
                return false;
            }
            // TODO: 校验token有效性，可以从redis中读取

            // 返回true表示这个token真实、有效
            return true;
        });
    }

}
